import * as THREE from 'three';

// 定义高层房子
const tallHouse = new THREE.Group();
tallHouse.name = 'tallHouse';
for (let index = 0; index < 5; index++) {
    const geometry = new THREE.BoxGeometry(50, 270, 50);
    const material = new THREE.MeshLambertMaterial({
        color: 0x669900,
    })
    const mesh = new THREE.Mesh(geometry, material);
    mesh.name = `tallHouse${index}`;
    mesh.position.set(index * 100, 0, 0);
    tallHouse.add(mesh);
}

// 定义矮层房子
const shortHouse = new THREE.Group();
shortHouse.name = 'shortHouse';
for (let index = 0; index < 5; index++) {
    const geometry = new THREE.BoxGeometry(50, 100, 50);
    const material = new THREE.MeshLambertMaterial({
        color: 0x669900,
    })
    const mesh = new THREE.Mesh(geometry, material);
    mesh.name = `shortHouse${index}`;
    mesh.position.set(index * 100, 0, 0);
    shortHouse.add(mesh);
}
shortHouse.position.z = 200
shortHouse.position.y = -85

const group = new THREE.Group();
group.add(tallHouse);
group.add(shortHouse);

const obj = group.getObjectByName('tallHouse0');
obj.material.color.set(0x55ff11);

group.traverse(node => {
    const house2 = node.getObjectByName('shortHouse2');
    if(house2) {
        house2.material.color.set(0x55ff11);
    }
})
export default group;